/**
 * This code is part of the Bumpslide Library by David Knape
 * http://bumpslide.com/
 * 
 * Copyright (c) 2006, 2007, 2008 by Bumpslide, Inc.
 * 
 * Released under the open-source MIT license.
 * http://www.opensource.org/licenses/mit-license.php
 * see LICENSE.txt for full license terms
 */ 
package 
{
	import com.bumpslide.events.UIEvent;
	import com.bumpslide.tween.FTween;
	import com.bumpslide.ui.Applet;
	import com.bumpslide.ui.Box;
	import com.bumpslide.util.GridLayout;

	import flash.display.Sprite;

	/**
	 * FTween Color Easing Test
	 * 
	 * This is also a nice barebones GridLayout Example
	 * 
	 * @mxmlc -sp=../../classes/ -default-frame-rate 31
	 * @author David Knape
	 */
	public class FTweenColorTest extends Applet {
		
		private var colors:Array = [ 0x880000, 0xcc4400, 0xeebb00, 0x008800, 0x113388, 0x331188, 0x774422, 0x333333 ]; 
		private var background:Box;
		private var buttons:Sprite;

		// create background and grid of color buttons
		override protected function addChildren () : void {
            
            background = new Box(0x333333);
            background.name = 'background'; // nice for traces
            addChild( background );  
            
            buttons = new Sprite();
            buttons.x = buttons.y = 10;
            addChild( buttons );
                        
            // use grid layout to place buttons and pass in color values
            var grid:GridLayout = new GridLayout( buttons, ColorButton, 64, 20);
            grid.dataProvider = colors;
                        
            // listen for grid item clicks            
            addEventListener( GridLayout.EVENT_ITEM_CLICK, onColorClick );            
		}
		
		// resize background on redraw
		override protected function draw() : void {
			background.width = width;
			background.height = height;
		}
		
		private function onColorClick(event:UIEvent):void {
			FTween.easeColor( background, 'color', event.data as Number, .05);
		}        
	}
}

import com.bumpslide.ui.Box;
import com.bumpslide.ui.GridItem;

import flash.filters.DropShadowFilter;


class ColorButton extends GridItem {
	
	private var border:Box;
	private var colorBox:Box;
	
	override protected function addChildren() : void {		
		
		// create border and color box
		border = new Box(0x000000, 60, 20);
		colorBox = new Box(0xaaaaaa, 58, 18);
		colorBox.x = colorBox.y = 1;
		addChild( border );
		addChild( colorBox );		
		
		// add drop shadow
		filters = [ new DropShadowFilter(1, 45, 0, 1, 3, 3, .5, 3) ];
	}
	
	override protected function draw() : void  {		
		colorBox.color = gridItemData as Number;
	}
	
}
